package com.zp.drug.impl;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Item {
    private String name;
    private int quantity;

    // 构造函数、getter和setter省略

    public Item(String name, int quantity) {
        this.name = name;
        this.quantity = quantity;
    }

    public static void main(String[] args) {
        List<Item> items = Arrays.asList(
                new Item("item1", 10),
                new Item("item2", -5),
                new Item("item3", 0),
                new Item("item4", -2),
                new Item("item5", 8)
        );

        Map<Boolean, List<Item>> groupedBySign = items.stream()
                .collect(Collectors.groupingBy(
                        item -> item.getQuantity() > 0,
                        Collectors.mapping(Function.identity(), Collectors.toList())
                ));

        // 正数分组
        List<Item> positiveItems = groupedBySign.getOrDefault(true, Collections.emptyList());
        // 负数分组
        List<Item> negativeItems = groupedBySign.getOrDefault(false, Collections.emptyList());

        // 输出结果
        System.out.println("Positive Items: " + positiveItems.toString());
        System.out.println("Negative Items: " + negativeItems.toString());
    }

    public int getQuantity() {
        return quantity;
    }
}